package magnata;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class WriteToFile {
	public WriteToFile()
	{
	
	}

	
	public void writeFile(String name, Object ob) throws IOException
	{
		FileOutputStream fos = new FileOutputStream(name);
	    ObjectOutputStream oos = new ObjectOutputStream(fos);
	    oos.writeObject(ob);
	    oos.close();
	}
	
	public Object readFile(String name){
		Object ob = new Object();
		
		FileInputStream fin;
		try {
			fin = new FileInputStream(name);
			ObjectInputStream ois;
			ois = new ObjectInputStream(fin);
			ob = ois.readObject();		
			ois.close();
			
		} catch (IOException | ClassNotFoundException e ) {
			e.printStackTrace();
		}
		
		return ob;
	}
	
}
